﻿
//#region 规则
var Rule = function (startActivity) {
    var canInfo = canvasHelper.InitialCanvas();
    this.guid = Guid.NewGuid();
    this.RuleProperty = {};
    this.RuleProperty.guid = this.guid;
    this.RuleProperty.ruleType = 0;
    this.RuleProperty.isDel = 0;
    this.RuleProperty.lineType = 0
    this.Points = new Array();
    this.startActivity = startActivity;
    this.endActivity = null;
    this.Canvas = canInfo.canvas;
    this.Picture = canInfo.cxt;
    this.isSelect = false;

    this.vextPosition = -1;
    this.capture = {
        iscapture: false,
        point: new Point(0, 0)
    }
}

Rule.prototype = {
    ChangeID: function () {
        var me = this;
        me.guid = Guid.NewGuid();
        me.RuleProperty.guid = me.guid;
    },

    SetProperty: function (property) {
        this.RuleProperty = property;
        if (property.guid != undefined) {
            this.guid = property.guid
            this.DrawRuleName('rgba(0,0,0,1)');
        }
    },

    DrawRule: function (currentPosition) {
        var me = this;
        var point;
        if (me.Points.length == 0) {
            point = currentRule.GetIntersectionPoint(me.startActivity, currentPosition);
        }
        else {
            point = me.Points[0];
        }
        var cxt = me.Picture;
        cxt.strokeStyle = 'rgba(0,0,0,1)';
        this.restore();
        cxt.moveTo(point.X, point.Y);
        for (i = 1; i < me.Points.length; i++)
            cxt.lineTo(me.Points[i].X, me.Points[i].Y);
        cxt.lineTo(currentPosition.X, currentPosition.Y);
        var arrow = Arrow(me.Points.length == 0 ? point : me.Points[me.Points.length - 1], currentPosition);
        cxt.lineTo(arrow.upArrow.X, arrow.upArrow.Y);
        cxt.moveTo(currentPosition.X, currentPosition.Y);
        cxt.lineTo(arrow.downArrow.X, arrow.downArrow.Y);
        cxt.stroke();

    },

    generateBackground: function (tmp) {
        var me = this;
        var fillStyle;

        if (tmp == undefined) {
            fillStyle = 'rgba(0,0,0,1)';
        }
        else fillStyle = tmp;
        return fillStyle;

    },


    //重置路径
    restore: function () {
        var cxt = this.Picture;
        cxt.clearRect(-100, -100, StyleDefine.Window.width + 100, StyleDefine.Window.height + 100);
        cxt.restore();
        cxt.beginPath();
    },

    ResetRule: function () {
        var me = this;
        var style = "rgba(0,0,0,1)";
        if (this.isSelect)
            style = "rgba(255,0,0,1)";

        style = me.generateBackground(style);

        this.Draw(style);
        if (this.isSelect)
            this.DrawCircle();
    },

    Draw: function (strokeStyle) {
        var me = this;
        var point = me.Points[0];
        var cxt = me.Picture;
        me.restore();
        cxt.strokeStyle = strokeStyle;
        cxt.moveTo(point.X, point.Y);
        for (i = 1; i < me.Points.length; i++)
            cxt.lineTo(me.Points[i].X, me.Points[i].Y);
        var arrow = Arrow(me.Points[me.Points.length - 2], me.Points[me.Points.length - 1]);
        cxt.lineTo(arrow.upArrow.X, arrow.upArrow.Y);
        cxt.moveTo(me.Points[me.Points.length - 1].X, me.Points[me.Points.length - 1].Y);
        cxt.lineTo(arrow.downArrow.X, arrow.downArrow.Y);
        cxt.stroke();
        me.DrawRuleName(strokeStyle);
    },

    ChangeSelectStatus: function () {
        var me = this;
        if (me.status != me.isSelect) {
            me.status = me.isSelect;
            this.ResetRule();
        }
    },

    nulloperation: function () { },

    ReSetStartPoint: function (currentPosition) {
        var me = this;
        if (me.Points.length > 2) {

            var flag1 = me.IsHorizontal(me.Points[0], me.Points[1]) && me.IsVertical(me.Points[1], me.Points[2]);
            var flag2 = me.IsVertical(me.Points[0], me.Points[1]) && me.IsHorizontal(me.Points[2], me.Points[1]);
            if (flag1 || flag2) {

            }
            else {
                me.nulloperation();
            }

            if (flag1) {
                me.Points[1].Y = currentPosition.Y;
            }

            if (flag2) {
                me.Points[1].X = currentPosition.X;

            }

            if (me.Points.length == 3) {
                var pointE = me.GetIntersectionPoint(me.endActivity, me.Points[1]);
                var pointS = me.GetIntersectionPoint(me.startActivity, me.Points[1]);
                me.Points[0] = pointS;
                me.Points[2] = pointE;
            }
            me.Points[0] = me.GetIntersectionPoint(me.startActivity, me.Points[1]);
        }
        else {
            var pointE = me.GetIntersectionPoint(me.endActivity, me.startActivity.position);
            var pointS = me.GetIntersectionPoint(me.startActivity, pointE);
            me.Points[0] = pointS;
            me.Points[1] = pointE;
        }
        me.ResetRule();
    },

    ReSetEndPoint: function (currentPosition) {


        var me = this;
        if (me.Points.length > 2) {
            if (me.IsHorizontal(me.Points[me.Points.length - 1], me.Points[me.Points.length - 2])
            && me.IsVertical(me.Points[me.Points.length - 2], me.Points[me.Points.length - 3])
            ) {
                me.Points[me.Points.length - 2].Y = currentPosition.Y;
            }
            if (me.IsVertical(me.Points[me.Points.length - 1], me.Points[me.Points.length - 2]) &&
            me.IsHorizontal(me.Points[me.Points.length - 2], me.Points[me.Points.length - 3])) {
                me.Points[me.Points.length - 2].X = currentPosition.X;
            }

            if (me.Points.length == 3) {
                var pointE = me.GetIntersectionPoint(me.endActivity, me.Points[1]);
                var pointS = me.GetIntersectionPoint(me.startActivity, me.Points[1]);
                me.Points[0] = pointS;
                me.Points[2] = pointE;
            }
            else
                me.Points[me.Points.length - 1] = me.GetIntersectionPoint(me.endActivity, me.Points[me.Points.length - 2]);
        }
        else {
            var pointE = me.GetIntersectionPoint(me.endActivity, me.startActivity.position);
            var pointS = me.GetIntersectionPoint(me.startActivity, pointE);
            me.Points[0] = pointS;
            me.Points[1] = pointE;
        }
        me.ResetRule();
    },


    IsHorizontal: function (p1, p2) {
        if (Math.abs(p1.Y - p2.Y) < 2)
            return true;
        return false;
    },

    IsVertical: function (p1, p2) {
        if (Math.abs(p1.X - p2.X) < 2)
            return true;
        return false;
    },

    ResetPoint: function (e) {
        var me = this;
        var point = canvasHelper.GetPoint(e);
        if (me.pointPosition != -1) {
            var ishandler = false;
            if (me.Points.length > 3) {
                if (me.vextPosition > 0 && me.vextPosition < me.Points.length - 1) {
                    if (me.vextPosition < me.Points.length - 2) {
                        if (me.IsHorizontal(me.Points[me.vextPosition - 1], me.Points[me.vextPosition]) && me.IsHorizontal(me.Points[me.vextPosition + 1], me.Points[me.vextPosition + 2])) {
                            me.Points[me.vextPosition].X = point.X;
                            me.Points[me.vextPosition + 1].X = point.X;
                            //me.SetStartEndPoint(point);
                            ishandler = true;
                        }
                        else if (me.IsVertical(me.Points[me.vextPosition - 1], me.Points[me.vextPosition]) && me.IsVertical(me.Points[me.vextPosition + 1], me.Points[me.vextPosition + 2])) {
                            me.Points[me.vextPosition].Y = point.Y;
                            me.Points[me.vextPosition + 1].Y = point.Y;
                            //me.SetStartEndPoint(point);
                            ishandler = true;
                        }
                    }
                    else if (me.vextPosition > 1) {
                        if (me.IsHorizontal(me.Points[me.vextPosition + 1], me.Points[me.vextPosition]) && me.IsHorizontal(me.Points[me.vextPosition - 1], me.Points[me.vextPosition - 2])) {
                            me.Points[me.vextPosition].X = point.X;
                            me.Points[me.vextPosition - 1].X = point.X;
                            //me.SetStartEndPoint(point);
                            ishandler = true;
                        }
                        else if (me.IsVertical(me.Points[me.vextPosition + 1], me.Points[me.vextPosition]) && me.IsVertical(me.Points[me.vextPosition - 1], me.Points[me.vextPosition - 2])) {
                            me.Points[me.vextPosition].Y = point.Y;
                            me.Points[me.vextPosition - 1].Y = point.Y;
                            //me.SetStartEndPoint(point);
                            ishandler = true;
                        }
                    }
                }


            }

            if (!ishandler) {
                me.Points[me.vextPosition] = point;
                me.SetStartEndPoint(point);
            }
            this.ResetRule();
            this.DrawCircle();
        }
    },


    SetStartEndPoint: function (point) {
        var me = this;
        if (me.vextPosition == 1) {
            me.Points[0] = me.GetIntersectionPoint(me.startActivity, point);
        }
        if (me.vextPosition == me.Points.length - 2) {
            me.Points[me.Points.length - 1] = me.GetIntersectionPoint(me.endActivity, point);
        }
    },

    AddPoint: function (point) {
        var me = this;
        if (me.capture.iscapture)
            point = me.capture.point;
        if (me.Points.length == 0)
            me.Points[0] = me.GetIntersectionPoint(me.startActivity, point);
        me.Points[me.Points.length] = point;

    },

    DrawCircle: function () {
        var rule = this;
        var cxt = rule.Picture;
        rule.ChangeSelectStatus(true);
        for (i = 0; i < rule.Points.length; i++) {
            cxt.DrawCircle(rule.Points[i].X, rule.Points[i].Y, 5, 'rgba(225,0,0,0.5)');
        }
    },

    SelectRule: function (result) {
        this.DrawCircle();
        gcommand = Command.SelectRule;
        if (result.selectType == 1) {
            moveRule = true;
            $("#divWorkspace").css("cursor", "move");
        }
    },
    //判断当前规则是否被鼠标点中
    IsSelect: function (point) {
        var result = {
            'isSelect': false,
            'selectedObject': null,
            'distinct': 1000,
            'vextdistinct': 1000,
            'selectType': 0
        };
        for (i = 1; i < this.Points.length; i++) {
            var dis = mathHelper.GetNearestDistance(this.Points[i - 1], this.Points[i], point);
            if (dis < result.distinct)
                result.distinct = dis;
            var vextdistinct = mathHelper.PointDistinct(point.X, point.Y, this.Points[i].X, this.Points[i].Y);
            var position = i;
            if (i == 1) {
                var vextdistinct1 = mathHelper.PointDistinct(point, this.Points[0]);
                if (vextdistinct1 < vextdistinct) {
                    vextdistinct = vextdistinct1;
                    position = 0;
                }
            }
            if (vextdistinct < result.vextdistinct) {
                result.vextdistinct = vextdistinct;
                this.vextPosition = position;
            }

        }
        if (result.distinct < 2 || result.vextdistinct < 5) {
            result.isSelect = true;
            result.selectedObject = this;
            result.selectType = result.vextdistinct < 5 ? 1 : 0;
        }




        return result;
    },

    ChangeActivity: function (point, result) {
        var me = this;
        if (me.vextPosition == me.Points.length - 1) {
            //更改endActivity
            if (result.isSelect) {
                me.endActivity.ToRule.Remove(this);
                me.endActivity = result.selectedObject;
                me.endActivity.ToRule[me.endActivity.ToRule.length] = this;
            }
            me.ReSetEndPoint(point);
        }
        else if (me.vextPosition == 0) {
            if (result.isSelect && result.selectedObject.CanHaveFromRule()) {

                me.startActivity.FromRule.Remove(this);
                me.startActivity = result.selectedObject;
                me.startActivity.FromRule[me.startActivity.FromRule.length] = this;
            }
            me.ReSetStartPoint(point);

        }
    },
    //获取所有线段中最长的一条
    DrawRuleName: function (strokeStyle) {

        var me = this;
        if (me.RuleProperty != undefined && me.RuleProperty.ruleName != undefined && me.RuleProperty.ruleName != '') {
            var tmp = 0;
            var dis = 0;
            var a = 0;
            while (a < me.Points.length - 1) {
                var tmpDis = mathHelper.PointDistinct(me.Points[a], me.Points[++a]);
                if (tmpDis > dis) {
                    dis = tmpDis;
                    tmp = a;
                }
            }
            var p1;
            var p2;
            if (tmp > 0) {
                if (me.Points[tmp - 1].X > me.Points[tmp].X) {
                    p2 = me.Points[tmp - 1];
                    p1 = me.Points[tmp];
                }
                else {
                    p1 = me.Points[tmp - 1];
                    p2 = me.Points[tmp];
                }
                //文字旋转角度
                var angle;

                var sincos = mathHelper.Angle(p1, p2);
                //0~180
                if (sincos.sin > 0) {
                    angle = Math.acos(sincos.cos);
                }
                    //180~360
                else if (sincos.sin < 0) {
                    angle = 2 * Math.PI - Math.acos(sincos.cos);
                }
                else {
                    if (sincos.cos == 1) angle = 0;
                    else if (sincos.cos == -1) angle = Math.PI;
                }
                me.Picture.save();
                me.Picture.translate(p1.X + Math.cos(angle) * dis / 3 + 10 * +Math.sin(angle), p1.Y + Math.sin(angle) * dis / 3 - 10 * Math.cos(angle));
                me.Picture.rotate(angle);
                me.Picture.fillStyle = strokeStyle;
                me.Picture.fillText(me.RuleProperty.ruleName, 0, 0);
                me.Picture.restore();
            }
        }
    },

    GetIntersectionPoint: function (activity, point) {

        if (activity.activityType == ActivityType.Start || activity.activityType == ActivityType.End || activity.activityType == ActivityType.Freedom) {
            var r;
            if (activity.activityType == ActivityType.Start) {
                r = StyleDefine.Activity.Start.Radius;
            }
            else if (activity.activityType == ActivityType.End) {
                r = StyleDefine.Activity.End.Radius;
            }

            else if (activity.activityType == ActivityType.Freedom) {
                r = StyleDefine.Activity.End.Radius;
            }
            point = new Point(point.X - activity.position.X, point.Y - activity.position.Y);
            var dis = mathHelper.PointDistinct(point.X, point.Y, 0, 0);

            var sin = point.X / dis;
            var cos = point.Y / dis;

            var resultX = r * sin + activity.position.X;
            var resultY = r * cos + activity.position.Y;
            return new Point(resultX, resultY);


        }

        else if (activity.activityType == ActivityType.Condition || activity.activityType == ActivityType.Merging || activity.activityType == ActivityType.Branching) {
            var p1;
            var p2;

            var width;
            var height;

            if (activity.activityType == ActivityType.Condition) {
                width = StyleDefine.Activity.Condition.diamondWidth;
                height = StyleDefine.Activity.Condition.diamondHeight;
            }
            else if (activity.activityType == ActivityType.Merging) {
                width = StyleDefine.Activity.Merging.diamondWidth;
                height = StyleDefine.Activity.Merging.diamondHeight;
            }
            else if (activity.activityType == ActivityType.Branching) {
                width = StyleDefine.Activity.Branching.diamondWidth;
                height = StyleDefine.Activity.Branching.diamondHeight;
            }


            if (point.X > activity.position.X) {
                //右侧偏下
                if (point.Y > activity.position.Y) {
                    p1 = new Point(0, height);
                    p2 = new Point(width, 0);
                }
                else if (point.Y == activity.position.Y) {
                    return new Point(activity.position.X + width, activity.position.Y)

                }
                    //右侧偏上
                else {
                    p1 = new Point(0, -height);
                    p2 = new Point(width, 0);

                }
            }
            else if (point.X == activity.position.X) {
                if (point.Y > activity.position.Y)
                    return new Point(activity.position.X, activity.position.Y + height);
                else return new Point(activity.position.X, activity.position.Y - height);
            }
            else {
                //左侧偏上
                if (point.Y > activity.position.Y) {
                    p1 = new Point(-width, 0);
                    p2 = new Point(0, height);
                }
                else if (point.Y == activity.position.Y) {
                    return new Point(activity.position.X - width, activity.position.Y);
                }

                else {
                    p1 = new Point(-width, 0),
                          p2 = new Point(0, -height)
                }
            }

            return mathHelper.GetIntersectionPoint(activity.position, point, p1, p2);

        }

        else {

            var activityRectVertexY;
            var activityRectVertexX;
            var r;
            if (activity.activityType == ActivityType.Drafting) {
                activityRectVertexY = StyleDefine.Activity.Drafting.activityRectVertexY;
                activityRectVertexX = StyleDefine.Activity.Drafting.activityRectVertexX;
                r = StyleDefine.Activity.Drafting.activityRectAngle;
            }
            else if (activity.activityType == ActivityType.Approval) {
                activityRectVertexY = StyleDefine.Activity.Approval.activityRectVertexY;
                activityRectVertexX = StyleDefine.Activity.Approval.activityRectVertexX;
                r = StyleDefine.Activity.Approval.activityRectAngle;
            }
            //以当前顶点为坐标系
            var relativeCoordinates = new Point(point.X - activity.position.X, point.Y - activity.position.Y);
            var me = this;
            var k = 0;

            if (relativeCoordinates.X != 0) {
                k = relativeCoordinates.Y / relativeCoordinates.X;
            }
            //鼠标在节点的右侧
            if (relativeCoordinates.X > 0) {
                //                    activityRectVertexX
                //                    activityRectVertexY
                //右侧偏下
                if (relativeCoordinates.Y > 0) {
                    var y1 = activityRectVertexY;
                    var x1 = y1 / k;
                    var result = new Point(x1, y1);
                    var center = new Point(activityRectVertexX - r, activityRectVertexY - r);
                    if (x1 > activityRectVertexX) {
                        //在弧上
                        result.X = activityRectVertexX;
                        result.Y = k * result.X;
                    }
                    if (result.X > center.X && result.Y > center.Y) {

                        var tmp = mathHelper.LineCircleIntersection(center, r, k, relativeCoordinates);
                        if (tmp != null)
                            result = tmp;
                    }
                    return result.MovePoint(activity.position);

                }

                else if (relativeCoordinates.Y == 0) {
                    return new Point(activity.position.X + activityRectVertexX, activity.position.Y);
                }
                    //右侧偏上
                else {
                    var y1 = -activityRectVertexY;

                    var x1 = y1 / k;

                    var result = new Point(x1, y1);

                    var center = new Point(activityRectVertexX - r, -activityRectVertexY + r);

                    if (result.X > center.X) {
                        result.X = activityRectVertexX;
                        result.Y = k * result.X;
                    }

                    if (result.X > center.X && result.Y < center.Y) {
                        var tmp = mathHelper.LineCircleIntersection(center, r, k, relativeCoordinates);
                        if (tmp != null)
                            result = tmp;
                    }

                    return result.MovePoint(activity.position);
                }
            }
            else if (relativeCoordinates.X == 0) {
                if (relativeCoordinates.Y > 0) {
                    return new Point(activity.position.X, activity.position.Y + activityRectVertexY);
                }
                else { return new Point(activity.position.X, activity.position.Y - activityRectVertexY); }

            }
            else {
                //左侧偏上
                if (relativeCoordinates.Y > 0) {
                    var y1 = activityRectVertexY;
                    var x1 = y1 / k;
                    var result = new Point(x1, y1);
                    var center = new Point(-activityRectVertexX + r, activityRectVertexY - r);
                    if (x1 < -activityRectVertexX) {
                        result.X = -activityRectVertexX;
                        result.Y = k * result.X;
                    }

                    if (result.X < center.X && result.Y > center.Y) {

                        var tmp = mathHelper.LineCircleIntersection(center, r, k, relativeCoordinates);
                        if (tmp != null)
                            result = tmp;
                    }
                    return result.MovePoint(activity.position);
                }
                else if (relativeCoordinates.Y == 0) {
                    return new Point(activity.position.X - activityRectVertexX, activity.position.Y);
                }

                else {
                    var y1 = -activityRectVertexY;
                    var x1 = y1 / k;
                    var result = new Point(x1, y1);
                    var center = new Point(-activityRectVertexX + r, -activityRectVertexY + r);
                    if (x1 < -activityRectVertexX) {
                        if (x1 < -activityRectVertexX + r) {
                            result.X = -activityRectVertexX;
                            result.Y = k * result.X;
                        }
                    }
                    if (result.X < center.X && result.Y < center.Y) {
                        var tmp = mathHelper.LineCircleIntersection(center, r, k, relativeCoordinates);
                        if (tmp != null) result = tmp;
                    }
                    return result.MovePoint(activity.position);
                }
            }
        }

    },

    //currentPosition,鼠标当前位置
    DrawReferenceLine: function (currentPosition) {
        var me = this;
        var count = 0;
        var point;
        if (me.Points.length == 0)
            point = me.startActivity.position;
        else point = me.Points[me.Points.length - 1];
        me.IsCapture(currentPosition, point)
        var xd = false;
        var yd = false;


        var captureX = canvasHelper.GetCaptureActivity('IsCaptureX', currentPosition);


        var captureY = canvasHelper.GetCaptureActivity('IsCaptureY', currentPosition);

        if (captureX != null && captureX.iscapture) {
            me.Picture.DrawLine(new Point(captureX.point.X, 0), new Point(captureX.point.X, StyleDefine.Window.height), StyleDefine.Activity.referenceLineStyle);
            canvasHelper.DrawFocusInvoke(me.Picture, captureX.activity);
            if (this.capture.direct == 'y')
                xd = true;
        }
        if (captureY != null && captureY.iscapture) {
            me.Picture.DrawLine(new Point(0, captureY.point.Y), new Point(StyleDefine.Window.width, captureY.point.Y), StyleDefine.Activity.referenceLineStyle);
            canvasHelper.DrawFocusInvoke(me.Picture, captureY.activity);
            if (this.capture.direct == 'x')
                yd = true;
        } //存在交叉点,在交叉点出绘制


        var point = null;
        if (this.capture.iscapture && xd)
            point = new Point(captureX.point.X, this.capture.point.Y);
        else if (this.capture.iscapture && yd)
            point = new Point(this.capture.point.X, captureY.point.Y);
        else if (this.capture.iscapture)
            point = this.capture.point;
        else if (xd)
            point = captureX.point;
        else if (yd)
            point = captureY.point;
        if (point != null) {
            this.capture.iscapture = true;
            this.capture.point = point;
            this.DrawMovePoint(point);
        }
    },

    //currentPosition当前位置
    //point参考点
    IsCapture: function (currentPosition, point) {
        var cxt = this.Picture;
        cxt.strokeStyle = StyleDefine.Rule.referenceLineStyle;
        cxt.restore();
        cxt.beginPath();

        this.capture = {
            'iscapture': false,
            'point': null,
            'direct': null
        }

        if (mathHelper.PointDistinct(currentPosition, new Point(point.X, currentPosition.Y)) < 10) {
            cxt.moveTo(point.X, 0);
            cxt.lineTo(point.X, StyleDefine.Window.height);
            this.capture = {
                'iscapture': true,
                'point': new Point(point.X, currentPosition.Y),
                'direct': 'x'
            }
            cxt.stroke();
        }
        else if (mathHelper.PointDistinct(currentPosition, new Point(currentPosition.X, point.Y)) < 10) {
            cxt.moveTo(0, point.Y);
            cxt.lineTo(StyleDefine.Window.width, point.Y);
            this.capture = {
                'iscapture': true,
                'point': new Point(currentPosition.X, point.Y),
                'direct': 'y'
            }
            cxt.stroke();
        }
        return this.capture;
    },

    DrawMovePoint: function (point) {
        var x1 = point.X - StyleDefine.Rule.capturelength;
        var y1 = point.Y - StyleDefine.Rule.capturelength;
        var cxt = this.Picture;
        cxt.strokeStyle = StyleDefine.Rule.strokeStyle;
        cxt.beginPath();
        cxt.rect(x1, y1, 2 * StyleDefine.Rule.capturelength, 2 * StyleDefine.Rule.capturelength);
        cxt.stroke();
    },

    ShowProperty: function () {

        var me = this;


        var layerNum = $.layer({
            type: 1,
            title: false,
            move: [$("#divRulePropertyTitle"), true],
            fix: false,
            closeBtn: false,
            shadeClose: true,
            shade: [0.5, '#000', true],
            border: [5, 0.3, '#666', true],
            offset: ['50%', '50%'],
            area: ['690px', '190px'],
            page: { dom: $("#divRuleProperty") },
            success: function () {
            }
        });
        $(".xubox_main").css("background-color", "transparent");
        ruleProperty.InitialPage(this);
        $("#btnRulePropertyOK").unbind();
        $("#btnRulePropertyCancel").unbind();
        $("#btnRulePropertyOK").click(function () {

            ruleProperty.SaveData(me);
            layer.close(layerNum);
        });
        $("#btnRulePropertyCancel").click(function () { layer.close(layerNum); });



    },

    Dispose: function (force) {
        var me = this;
        if (force != undefined || me.startActivity.activityType != ActivityType.Start) {
            me.startActivity.FromRule.Remove(this);
            if (me.endActivity != undefined)
                me.endActivity.ToRule.Remove(this);
            me.Canvas.remove();
            me.Canvas = null;
            rules.Remove(me);
        }
        else {
            window.alert("此规则不能删除");
        }
    },

    Validate: function () { }
}
//#endregion